<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>添加组件</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon"/>
    <link rel="stylesheet" href="../css/font.css">
    <link rel="stylesheet" href="../css/xadmin.css">
    <script type="text/javascript"
            src="../lib/vue/jquery.min.js"></script>
    <script type="text/javascript" src="../lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="../js/xadmin.js"></script>
    <script type="text/javascript" src="../js/global.js"></script>
    <script type="text/javascript" src="../js/store.js"></script>
    <script type="text/javascript" src="../js/cookies.js"></script>
    <script src="../lib/vue/vue.min.js"></script>
    <script src="../lib/vue/axios.min.js"></script>
</head>

<body>
<div class="x-body layui-anim layui-anim-up">
    <form class="layui-form">
        <div class="layui-form-item" hidden>
            <div class="layui-input-inline">
                <input type="text" id="L_componentId" name="componentId" required=""
                       lay-verify=""
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item" hidden>
            <div class="layui-input-inline">
                <input type="text" id="L_componentName" name="componentName" required=""
                       lay-verify=""
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="L_versionNo" class="layui-form-label">
                <span class="x-red">*</span>组件版本
            </label>
            <div class="layui-input-inline" style="width: 300px;">
                <input type="text" id="L_versionNo" name="versionNo" required=""
                       lay-verify="versionNo"
                       autocomplete="off" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red">*</span>非空，版本前不加V
            </div>
        </div>
        <div class="layui-form-item">
            <label for="L_access" class="layui-form-label">
                <span class="x-red">*</span>接入方式
            </label>
            <div class="layui-input-inline" style="width: 300px;">
                <textarea id="L_access" name="accessInfo" required=""
                          lay-verify="accessInfo" class="layui-textarea"></textarea>
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red">*</span>非空
            </div>
        </div>
        <div class="layui-form-item">
            <label for="L_bestPractice" class="layui-form-label">
                <span class="x-red">*</span>最佳实践
            </label>
            <div class="layui-input-inline" style="width: 300px;">
                <textarea id="L_bestPractice" name="bestPractice" required=""
                          lay-verify="bestPractice" class="layui-textarea"></textarea>
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red">*</span>非空
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">
            </label>
            <button class="layui-btn" lay-filter="add" lay-submit="">
                新增
            </button>
        </div>
    </form>
</div>
<script>
    layui.use(['form', 'layer'], function () {
        $ = layui.jquery
        var form = layui.form
            , layer = layui.layer
        var editData = parent.parent.$("#editComponent").val();
        var editArray = JSON.parse(editData)
        $('#L_componentId').val(editArray.id)
        $('#L_componentName').val(editArray.componentName)

        //自定义验证规则
        form.verify({
            versionNo: function (value) {
                if (value.length < 1) {
                    return '组件版本不可为空'
                }
            },
            accessInfo: function (value) {
                if (value.length < 1) {
                    return '组件接入方式不可为空'
                }
            },
            bestPractice: function (value) {
                if (value.length < 1) {
                    return '组件最佳实践信息不可为空'
                }
            }
        });
        //监听提交
        form.on('submit(add)', function (data) {
            $.post(_hostUrl + "/cmsComponentInfo", data.field, function (res) {
                if (res.responseCode == 201) {
                    layer.msg('添加组件新版本成功', {
                        icon: 1,
                        time: 2000
                    }, function () {
                        //刷新父页面后关闭窗口
                        window.parent.location.reload();
                        var index = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(index);
                    });
                } else {
                    layer.msg(res.responseMsg, {icon: 2, time: 1500})
                }
            }, 'json');
            return false
        })

    })
</script>
</body>

</html>